﻿using System;
using System.Linq;
using NUnit.Framework;
using ProjetoComperio.Framework.Web.Logging;

namespace ProjetoComperio.Test.ComperioFramework.Web.Security
{
    [TestFixture]
    public class ExceptionLoggingAttributeTest
    {
        String exceptionID;

        [SetUp]
        public void SetUp()
        {
            exceptionID = DateTime.Now.ToString();
            //Assert.IsTrue(Logger.RetrieveExceptions().Any(ex => ex.Message.Contains(exceptionID)))
        }

        [Test]
        [ExpectedException(typeof(InvalidOperationException))]
        public void TestExceptionLoggingAttribute()
        {

            MyController controller = new MyController(exceptionID); ;
        }
        [Test]
        public void TestGetExceptions()
        {
            Assert.IsInstanceOf(typeof(IQueryable<global::ComperioFramework.Web.Logging.ExceptionLogging>), Logger.RetrieveExceptions());
        }
    }

    [ExceptionLogging]
    public class MyController : System.Web.Mvc.Controller
    {

        public MyController(String exceptionID)
        {
            throw new InvalidOperationException(exceptionID);
        }
    }
}
